<!DOCTYPE html>
<html>
<head>
  <title>indexedDB</title>
</head>
<body>
  <input data-status="当前行的状态" type="radio" value="" />
<script type="text/javascript">
  const request = indexedDB.open('indexedDB-test', 1);
  request.onsuccess = function(event) {
    let db = event.target.result;

    db.onsuccess = function(event) {
      console.log('DB connect success')
    }

    db.onerror = function(event) {
      console.log('DB err', event.target.errorCode)
    }

    db.transaction(['person'], 'readwrite')
    .objectStore('person')
    .add({ name: '张三', age: 24, email: 'zhangsan@example.com' });
    db.transaction(['person'], 'readwrite')
    .objectStore('person')
    .add({ name: '李四', age: 24, email: 'zhangsan@example.com' });
    console.log('222222', db.transaction)
  }

  request.onerror = function(event) {
    console.log('DB create error')
  }

  request.onupgradeneeded = function(event) {
    let database = event.target.result;
    let objectStore = database.createObjectStore('person', { keyPath: "id", autoIncrement: true })
    objectStore.createIndex('name', 'name', { unique: false });
    objectStore.createIndex('email', 'email', { unique: true });
    // objectStore.createIndex('jin', {data: 'title'}, {unique: true})

    console.log('222222', database.transaction)
  }

  class IndexedDBCrm {
    constructor() {
      this.db = null;
    }

    open(name, v) {
      this.db = indexedDB.open(name, v);

      return this;
    }
  }
  // window.addEventListener('mousemove', function(e) {
  //   console.log('e', e)
  // })

  // document.getElementById('btn').onclick = function() {
  //   // 先取消所有的禁用状态
  //   // 获取data-status的数据

  //   // 调用 state[status](status)
  //   var state = {
  //     0: function() {},
  //     1: function() {},
  //     2: function() {},
  //   }
  // }

  let str = JSON.stringify({a:1,b:2})
  console.log(str)
</script>
</body>
</html>